
let QQMapWX = require("./utils/qqmap-wx-jssdk.min.js");
var qqmapsdk;
App({
  onLaunch: function () {
    // 获取缓存中用户信息
    let user_info = wx.getStorageSync('user_info');
    if(user_info){
      this.common.user_info =user_info
    }else{
      this.common.user_info ={
        nickname:'未登录',
        no_login:true,
        headimgurl:'http://img.gek6.com/FnzCBkjI6ByH69cvpiYS8XMdXytx'
      }
    }
    
    // 更新全局变量中的token
    this.common.token =  wx.getStorageSync('token')
    qqmapsdk = new QQMapWX({
      key: 'E7LBZ-2GLK5-P4SIG-QXJPX-CFN7H-JUBMB'
    });
  
    
  },
  base_url:"https://api.letouhr.com/",
 
  // 获取当前位置，并转化为文字地址
  get_location_to_city(){
    let that = this;
    return new Promise(function(resolve,reject){
      wx.getLocation({
        type: 'wgs84',
        success (res) {
          let latitude = res.latitude
          let longitude = res.longitude
          that.common.now_position.lat = latitude;
          that.common.now_position.lng = longitude;
          wx.request({
            url: that.base_url+'lbs/location', //仅为示例，并非真实的接口地址
            data: {
              latitude,
              longitude
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            success (res) {
              // console.log(res.data);
              resolve(res.data)
            }
          })
        }
       })
    })

    
  },
  toast(msg, type) {
    if (!type) {
      type = null
    }
    switch (type) {
      case 'succ':
        wx.showToast({
          title: msg,
          icon: 'success',
          duration: 2000
        })
        break;
      case 'load':
        wx.showToast({
          title: msg,
          icon: 'loading',
          duration: 2000
        })
        break;

      default:
        wx.showToast({
          title: msg,
          icon: 'none',
          duration: 2000
        })
        break;
    }


  },
  // map-sdk 经纬度转详细地址
	position_to_address(opt){
		let that = this;
		return new Promise(function(resolve,reject){
			qqmapsdk.reverseGeocoder({
				location:opt.lat+","+opt.lng,
				success(res){
					console.log(res);
				}
			})
		})
		
	},
	common: {
    user_info: '',//用户账户信息
    token: '',//令牌
    now_city:{//当前城市数据
      name:'定位中..'
    },
    index_data:{

    },
    now_position:{
      lat:'',
      lng:''
    }
  }
})